/**
 * 
 */

var pageii = null;
var grid = null;
$(function() {
//	layer.msg("role list");
	
    grid = lyGrid({
        id : 'paging',
        height : '100%', // 表格宽度
        theadHeight : '28px', // 表格的thead高度
        tbodyHeight : '27px',// 表格body的每一行高度
//        isFixed : true,// 是
        checkValue : "id",
        l_column : [{
            colkey : "loginName",
            name : "账号",
        }, {
            colkey : "userName",
            name : "用户名"
        }, {
            colkey : "mobile",
            name : "手机号码",
            isSort : true,
//        }, {
//            colkey : "marketCode",
//            name : "推广码",
//        }, {
//            colkey : "schoolName",
//            name : "所在园所",
//        }, {
//            colkey : "lastLoginTime",
//            name : "最近登录时间",
        }, {
            colkey : "",
            name : "操作",
            renderData : function(rowindex ,data, rowdata, colkey){
                var id = rowdata.id;
                var isEnable = rowdata.isEnable;
                var html = "";
                if(isEnable == 1){
                    html += "<button type=\"button\" class=\"btn btn-danger\" onclick=\"updateEnable('" + id + "', '0')\">冻结</button>";
                }else{
                    html += "<button type=\"button\" class=\"btn btn-success\" onclick=\"updateEnable('" + id + "', '1')\">解冻</button>";
                }
                html += "<button type=\"button\" class=\"btn btn-info\" onclick=\"resetPasswd('" + id + "')\">重置密码</button>";
                return html;
      }
        }],
        jsonUrl : rootPath + '/sys/appUser/findByPage',
        checkbox : false,
    });
    
    $("#search").click("click", function() {// 绑定查询按扭
        var searchParams = $("#searchForm").serializeJson();// 初始化传参数
        grid.setOptions({
            data : searchParams
        });
    });

});

//更新冻结状态
function updateEnable(id, isEnable){
    var str = "<span style='padding: 5px'>冻结</span>";
    if(isEnable == 1){
        str = "<span style='padding: 5px'>解冻</span>";
    }
    var msg = "确定" + str + "账号？"
    layer.confirm(msg, function(index) {
        var url = rootPath + '/sys/appUser/updateEnable';
        var res = CommnUtil.ajax(url, {
            "id" : id,
            "isEnable" : isEnable
        });
        if (res == "success") {
            layer.msg(str + '成功!');
            grid.loadData();
        } else {
            layer.msg(str + '失败!');
        }
    });
}

//重置用户密码
function resetPasswd(id){
    layer.confirm("确定重置用户密码为'123456'?", function(index) {
        var url = rootPath + '/sys/appUser/resetPasswd';
        var res = CommnUtil.ajax(url, {
            "id" : id
        });
        if (res == "success") {
            layer.msg('重置用户密码成功!');
            grid.loadData();
        } else {
            layer.msg('重置用户密码失败!');
        }
     });
}